
package main;

import core.COINCOMOComponent;
import core.COINCOMOSubComponent;
import core.COINCOMOSubSystem;
import core.COINCOMOSystem;
import core.COINCOMOUnit;
import database.COINCOMOSystemManager;
import dialogs.AboutUsDialog;
import dialogs.ConnectDialog;
import dialogs.EAFDialog;
import dialogs.EquationEditorDialog;
import dialogs.FunctionPointsDialog;
import dialogs.ScaleFactorsDialog;
import dialogs.ViewCotsProjectsDialog;
import dialogs.ViewProjectsDialog;
import extensions.COINCOMOTreeNode;
import java.awt.Color;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import panels.HierarchyPanel;
import panels.MultipleBuildsGraphPanel;
import panels.OverviewsAndGraphsPanel;

/**
 *
 * @author Raed Shomali
 */
public class MenuItemMethods
{
    private static LookAndFeel defaultUI = UIManager.getLookAndFeel();

    static DecimalFormat format1Decimal = new DecimalFormat( "0.0" );
    static DecimalFormat format2Decimals = new DecimalFormat( "0.00" );
    static DecimalFormat format3Decimals = new DecimalFormat( "0.000" );

    public static void connectToDatabase()
    {
        new ConnectDialog( COINCOMO.application );
    }

    public static void disconnectFromDatabase( boolean showStatus )
    {
        COINCOMO.disconnectDatabaseMenuItem.setEnabled( false );

        COINCOMO.newProjectMenuItem.setEnabled( false );
        COINCOMO.viewProjectsMenuItem.setEnabled( false );
        COINCOMO.viewCotsProjectsMenuItem.setEnabled( false );
        COINCOMO.exportProjectMenuItem.setEnabled( false );

        COINCOMO.effortAdjustmentFactorsMenuItem.setEnabled( false );
        COINCOMO.scaleFactorsMenuItem.setEnabled( false );
        COINCOMO.equationEditorMenuItem.setEnabled( false );
        COINCOMO.functionPointsMenuItem.setEnabled( false );
        COINCOMO.personMonthMenuItem.setEnabled( false );

        // Clear Tree
        DefaultTreeModel model = (DefaultTreeModel) HierarchyPanel.tree.getModel();
        model.setRoot( null );

        HierarchyPanel.tree.setEnabled( false );

        HierarchyPanel.addSubSystemButton.setEnabled( false );
        HierarchyPanel.addComponentButton.setEnabled( false );
        HierarchyPanel.deleteSubSystemButton.setEnabled( false );
        HierarchyPanel.deleteComponentButton.setEnabled( false );

        OverviewsAndGraphsPanel.tabs.setEnabled( false );

        // If Tabs Exist ...
        if ( OverviewsAndGraphsPanel.tabs.getTabCount() > 0 )
        {
            OverviewsAndGraphsPanel.clearOverviewTab();
        }

        if ( showStatus )
        {
            GlobalMethods.updateStatusBar( "Disconnected From Database." );
        }
    }

    public static void createNewProject()
    {
        COINCOMOSystem system = COINCOMOSystemManager.insertSystem();

        if ( system != null )
        {
            // New Root with New System
            HierarchyPanel.root = new COINCOMOTreeNode( system );

            // Update Tree
            DefaultTreeModel model = (DefaultTreeModel) HierarchyPanel.tree.getModel();
            model.setRoot( HierarchyPanel.root );

            HierarchyPanel.tree.setSelectionPath( new TreePath( HierarchyPanel.root.getPath() ) );

            GlobalMethods.updateStatusBar( "New Project Created." );
        }
        else
        {
            GlobalMethods.updateStatusBar( "Could NOT Create a New Project, Please Verify the Parameters in the \'Connect Dialog\'" , Color.RED );
        }
    }

    public static void ViewProjects()
    {
        new ViewProjectsDialog( COINCOMO.application );
    }
    
    public static void ViewCotsProjects()
    {
    	new ViewCotsProjectsDialog( COINCOMO.application );
    }
    
    public static void ViewCotsProjects(COINCOMOComponent component)
    {
    	new ViewCotsProjectsDialog( COINCOMO.application, component );
    }

    public static void exportProjectAsCVS()
    {
        if ( HierarchyPanel.root == null )
        {
            GlobalMethods.updateStatusBar( "No System has been Opened to read from" , Color.RED );

            return;
        }

        try
        {
            JFileChooser fc = new JFileChooser();

            // For Example, Windows OS's UI
            setOperatingSystemUI();

            fc.updateUI();

            GlobalMethods.updateStatusBar( "Done." );

            fc.setSelectedFile( new File( "Project.csv" ) );

            // Show open dialog; this method does not return until the dialog is closed
            int result = fc.showSaveDialog( COINCOMO.application );

            if ( result == JFileChooser.APPROVE_OPTION )
            {
                // Has to be an XML Document
                if ( fc.getSelectedFile().getName().endsWith( ".csv" ) )
                {
                    BufferedWriter out = new BufferedWriter( new FileWriter( fc.getSelectedFile() ) );

                    COINCOMOSystem system = (COINCOMOSystem) HierarchyPanel.root.getCOINCOMOUnit();

                    out.write( "COINCOMO\n\n" );

                    out.write( "System\n" );
                    out.write( "ID , Name , SLOC , Cost , Staff\n" );
                    out.write( system.getUnitID() + " , " + system.getName() + " , " + system.getFinalSLOC() + " , " + system.getCost() + " , " + system.getStaff() + "\n\n" );

                    Vector<COINCOMOUnit> orderedSubSystemsVector = GlobalMethods.getOrderedVector( system.getListOfSubUnits() );

                    for ( int i = 0 ; i < orderedSubSystemsVector.size() ; i++ )
                    {
                        COINCOMOSubSystem subSystem = (COINCOMOSubSystem) orderedSubSystemsVector.get( i );

                        out.write( " , SubSystem\n" );
                        out.write( " , ID , Name , SLOC , Cost , Staff\n" );
                        out.write( " , " + subSystem.getUnitID() + " , " + subSystem.getName() + " , " + subSystem.getFinalSLOC() + " , " + subSystem.getCost() + " , " + subSystem.getStaff() + "\n\n" );

                        Vector<COINCOMOUnit> orderedComponentsVector = GlobalMethods.getOrderedVector( subSystem.getListOfSubUnits() );

                        for ( int j = 0 ; j < orderedComponentsVector.size() ; j++ )
                        {
                            COINCOMOComponent component = (COINCOMOComponent) orderedComponentsVector.get( j );

                            out.write( " , , Component\n" );
                            out.write( " , , ID , Name , SLOC , Cost , Staff , Effort , InstCost , PROD , Schedule , ScaleFactor\n" );
                            out.write( " , , " + component.getUnitID() + " , " + component.getName() + " , " + component.getFinalSLOC() + " , " + component.getCost() + " , " + component.getStaff() + " , " + component.getTotalEffort() + " , " + component.getTotalInstCost() + " , " + component.getTotalProd() + " , " + component.getTotalSchedule() + " , " + component.getScaleFactor() + "\n" );
                            out.write( " , , Inception\n" );
                            out.write( " , , Effort , Month , Personnel , EffortPercentage , SchedulePercentage\n" );
                            out.write( " , , " + component.getInceptionPM() + " , " + component.getInceptionM() + " , " + component.getInceptionP() + " , " + component.getInceptionEffortPercentage() + " , " + component.getInceptionSchedulePercentage() + "\n" );
                            out.write( " , , Elaboration\n" );
                            out.write( " , , Effort , Month , Personnel , EffortPercentage , SchedulePercentage\n" );
                            out.write( " , , " + component.getElaborationPM() + " , " + component.getElaborationM() + " , " + component.getElaborationP() + " , " + component.getElaborationEffortPercentage() + " , " + component.getElaborationSchedulePercentage() + "\n" );
                            out.write( " , , Construction\n" );
                            out.write( " , , Effort , Month , Personnel , EffortPercentage , SchedulePercentage\n" );
                            out.write( " , , " + component.getConstructionPM() + " , " + component.getConstructionM() + " , " + component.getConstructionP() + " , " + component.getConstructionEffortPercentage() + " , " + component.getConstructionSchedulePercentage() + "\n" );
                            out.write( " , , Transition\n" );
                            out.write( " , , Effort , Month , Personnel , EffortPercentage , SchedulePercentage\n" );
                            out.write( " , , " + component.getTransitionPM() + " , " + component.getTransitionM() + " , " + component.getTransitionP() + " , " + component.getTransitionEffortPercentage() + " , " + component.getTransitionSchedulePercentage() + "\n\n" );
                            
                            Vector<COINCOMOUnit> orderedSubComponentsVector = GlobalMethods.getOrderedVector( component.getListOfSubUnits() );

                            for ( int c = 0 ; c <
                                    orderedSubComponentsVector.size() ; c++ )
                            {
                                COINCOMOSubComponent subComponent = (COINCOMOSubComponent) orderedSubComponentsVector.get( c );

                                out.write( " , , , SubComponent\n" );
                                out.write( " , , , ID , Name , Language , SLOC , Cost , Staff , EAF , LaborRate , NomEffort , EstEffort , PROD , RISK , AssessmentAssimilation , AutoTranslationProductivity , AutomaticallyTranslated , Breakage , ChangeMultiplier , CodeModified , DesignModified , IntegrationModified , SoftwareUnderstanding , Unfamiliarity\n" );
                                out.write( " , , , " + subComponent.getUnitID() + " , " + subComponent.getName() + " , " + subComponent.getLanguage() + " , " + subComponent.getFinalSLOC() + " , "+ subComponent.getCost() + " , " + subComponent.getStaff() + " , " + subComponent.getEaf() + " , " + subComponent.getLaborRate() + " , " + subComponent.getNomEffort() + " , " + subComponent.getEstEffort() + " , " + subComponent.getProd() + " , " + subComponent.getRisk() + " , " + subComponent.getAssementAssimilation() + " , " + subComponent.getAutoTranslationProductivity() + " , " + subComponent.getAutomaticallyTranslated() + " , " + subComponent.getBreakage() + " , " + subComponent.getChangeMultiplier() + " , " + subComponent.getCodeModified() + " , " + subComponent.getDesignModified() + " , " + subComponent.getIntegrationModified() + " , " + subComponent.getSoftwareUnderstanding() + " , " + subComponent.getUnfamiliarity() + "\n\n" );
                            }

                            out.write( "\n" );
                        }

                        out.write( "\n" );
                    }

                    out.write( "\n" );

                    out.flush();

                    // Free Resources ..
                    out.close();

                    
                    // MultiBuild Report Section
                    
                    File multiBuildReport = new File( fc.getSelectedFile().getAbsolutePath().substring( 0 , fc.getSelectedFile().getAbsolutePath().indexOf( "." ) ) + "'s Multibuild Report.csv" )  ;
                    
                    BufferedWriter out2 = new BufferedWriter( new FileWriter( multiBuildReport ) );

                    // Traverse Subsystems ..
                    for ( int i = 0 ; i < orderedSubSystemsVector.size() ; i++ )
                    {
                        COINCOMOSubSystem subSystem = (COINCOMOSubSystem) orderedSubSystemsVector.get( i );
                     
                        out2.write( "Subsystem: " + subSystem.getName() + "\n\n" );
                        
                        Vector<COINCOMOUnit> orderedComponentsVector = GlobalMethods.getOrderedVector( subSystem.getListOfSubUnits() );

                        int indents = 0 ;
                        
                        COINCOMOComponent previousComponent = null ;
                        
                        // Traverse Components ..
                        for ( int j = 0 ; j < orderedComponentsVector.size() ; j++ )
                        {
                            COINCOMOComponent component = (COINCOMOComponent) orderedComponentsVector.get( j );
                            
                            // Except the First Component ...
                            if( j != 0 )
                            {
                                // To Determine How Much Indentation is Needed ...
                                
                                // Clear ..
                                int startingPoint = previousComponent.getMultiBuildShift();

                                // Inception
                                int inceptionSize = (int) ( previousComponent.getInceptionSchedulePercentage() / 100 * previousComponent.getFinalSLOC() * MultipleBuildsGraphPanel.minimizeFactor  );
                                int inceptionEndPoint = startingPoint + inceptionSize ;

                                // Elaboration
                                int elaborationSize = (int) ( previousComponent.getElaborationSchedulePercentage() / 100 * previousComponent.getFinalSLOC() * MultipleBuildsGraphPanel.minimizeFactor ) ;
                                int elaborationEndPoint = startingPoint + inceptionSize + elaborationSize ;

                                // Construction
                                int constructionSize = (int) ( previousComponent.getConstructionSchedulePercentage() / 100 * previousComponent.getFinalSLOC()* MultipleBuildsGraphPanel.minimizeFactor );
                                int constructionEndPoint = startingPoint + inceptionSize + elaborationSize + constructionSize ;

                                // Transition
                                int transitionSize = (int) ( previousComponent.getTransitionSchedulePercentage() / 100 * previousComponent.getFinalSLOC()* MultipleBuildsGraphPanel.minimizeFactor );
                                int transitionEndPoint = startingPoint + inceptionSize + elaborationSize + constructionSize + transitionSize ;
                                
                                
                                System.out.println( component.getMultiBuildShift() + " " + startingPoint + " " + inceptionEndPoint );
                                
                                if( component.getMultiBuildShift() >= startingPoint && component.getMultiBuildShift() < inceptionEndPoint )
                                {
                                    indents = indents + 0 ;
                                }
                                else if( component.getMultiBuildShift() >= inceptionEndPoint && component.getMultiBuildShift() < elaborationEndPoint )
                                {
                                    indents = indents + 1 ;
                                }
                                else if( component.getMultiBuildShift() >= elaborationEndPoint && component.getMultiBuildShift() < constructionEndPoint )
                                {
                                    indents = indents + 2 ;
                                }
                                else if( component.getMultiBuildShift() >= constructionEndPoint && component.getMultiBuildShift() < transitionEndPoint )
                                {
                                    indents = indents + 3 ;
                                }
                                else
                                {
                                    indents = indents + 4 ;
                                }
                            }
                            
                            StringBuilder indentation = new StringBuilder() ;
                            
                            // Do the Indentations ...
                            for( int c = 0 ; c < indents ; c ++ )
                            {
                                indentation.append( "," );
                            }
                            
                            out2.write( indentation.toString() +" , "+ "Inception , Elaboration , Construction , Transition , Total E&C , Total , , , Component: " + component.getName() + "\n" );
                            out2.write( indentation.toString() +"Schedule"+" , "+ GlobalMethods.roundOff( (float)component.getInceptionEffortPercentage(), 2 ) + " , "  
                                    + GlobalMethods.roundOff( (float)component.getElaborationEffortPercentage(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getConstructionEffortPercentage(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getTransitionEffortPercentage(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getPMTotalEC(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getPMTotal(), 2 ) + " , " 
                                    + "\n" );
                            out2.write( indentation.toString() +"Effort"+" , "+ GlobalMethods.roundOff( (float)component.getInceptionSchedulePercentage(), 2 ) + " , "  
                                    + GlobalMethods.roundOff( (float)component.getElaborationSchedulePercentage(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getConstructionSchedulePercentage(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getTransitionSchedulePercentage(), 2  ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getMTotalEC(), 2  ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getMTotal() , 2 ) + " , " 
                                    + "\n" );
                            out2.write( indentation.toString() +"PM"+" , "+GlobalMethods.roundOff( (float)component.getInceptionPM(), 2 ) + " , "  
                                    + GlobalMethods.roundOff( (float)component.getElaborationPM(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getConstructionPM(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getTransitionPM(), 2  ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getPMTotalEC(), 2  ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getPMTotal() , 2 ) + " , " 
                                    + "\n" );
                            out2.write( indentation.toString() +"M"+" , "+GlobalMethods.roundOff( (float)component.getInceptionM(), 2 ) + " , "  
                                    + GlobalMethods.roundOff( (float)component.getElaborationM(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getConstructionM(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getTransitionM(), 2  ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getMTotalEC(), 2  ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getMTotal() , 2 ) + " , " 
                                    + "\n" );
                            out2.write( indentation.toString() +"PM/M"+" , "+GlobalMethods.roundOff( (float)component.getInceptionP(), 2 ) + " , "  
                                    + GlobalMethods.roundOff( (float)component.getElaborationP(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getConstructionP(), 2 ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getTransitionP(), 2  ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getPTotalEC(), 2  ) + " , " 
                                    + GlobalMethods.roundOff( (float)component.getPTotal() , 2 ) + " , " 
                                    + "\n" );
                            
                            out2.write( "\n" ) ;
                            
                            previousComponent = component ;
                        }

                        out2.write( "\n\n" );
                    }
                    
                    out2.flush();

                    // Free Resources ..
                    out2.close();

                    
                    GlobalMethods.updateStatusBar( "Exporting had Finished." );
                }
                else
                {
                    GlobalMethods.updateStatusBar( "File has to be an CSV Document." , Color.RED );
                }

            }
        }
        catch ( IOException e )
        {
        }
        finally
        {
            // Go Back to Default
            setJavaUI();
        }
    }

    public static void exportProjectAsHTML()
    {
        if ( HierarchyPanel.root == null )
        {
            GlobalMethods.updateStatusBar( "No System has been Opened to read from" , Color.RED );

            return;
        }

        try
        {
            JFileChooser fc = new JFileChooser();

            // For Example, Windows OS's UI
            setOperatingSystemUI();

            fc.updateUI();

            GlobalMethods.updateStatusBar( "Done." );

            fc.setSelectedFile( new File( "Project.html" ) );

            // Show open dialog; this method does not return until the dialog is closed
            int result = fc.showSaveDialog( COINCOMO.application );

            if ( result == JFileChooser.APPROVE_OPTION )
            {
                // Has to be an XML Document
                if ( fc.getSelectedFile().getName().endsWith( ".html" ) )
                {
                    BufferedWriter out = new BufferedWriter( new FileWriter( fc.getSelectedFile() ) );

                    COINCOMOSystem system = (COINCOMOSystem) HierarchyPanel.root.getCOINCOMOUnit();

                    out.write( "<html>\n" );
                    out.write( "<head>\n" );
                    out.write( "<title>COINCOMO Project</title>\n" );
                    out.write( "<style type = 'text/css'>\n" );
                    out.write( "table	{ font-size:9pt; }\n" );
                    out.write( "td	{ font-family:courier; }\n" );

                    out.write( "a.system:link			{ color:black; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.system:visited       		{ color:black; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.system:hover         		{ color:black; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.system:active        		{ color:black; font-size:11pt; text-decoration:underline; }\n" );

                    out.write( "a.subsystem:link		{ color:red; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.subsystem:visited       	{ color:red; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.subsystem:hover         	{ color:red; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.subsystem:active        	{ color:red; font-size:11pt; text-decoration:underline; }\n" );

                    out.write( "a.component:link		{ color:green; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.component:visited       	{ color:green; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.component:hover         	{ color:green; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.component:active        	{ color:green; font-size:11pt; text-decoration:underline; }\n" );

                    out.write( "a.subcomponent:link		{ color:blue; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.subcomponent:visited       	{ color:blue; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.subcomponent:hover         	{ color:blue; font-size:11pt; text-decoration:underline; }\n" );
                    out.write( "a.subcomponent:active        	{ color:blue; font-size:11pt; text-decoration:underline; }\n" );

                    out.write( "</style>\n" );

                    out.write( "<script type = 'text/javascript'>\n" );

                    out.write( "function eventTrigger (e) \n" );
                    out.write( "{\n" );
                    out.write( "if( !e )\n" );
                    out.write( "{\n" );
                    out.write( "e = event;\n" );
                    out.write( "}\n" );
                    out.write( "return e.target || e.srcElement;\n" );
                    out.write( "}\n" );

                    out.write( "function displayInformation( e )\n" );
                    out.write( "{\n" );
                    out.write( "var obj = eventTrigger( e );\n" );
                    out.write( "if( obj.tagName != 'A' )\n" );
                    out.write( "{\n" );
                    out.write( "obj = obj.parentNode;\n" );
                    out.write( "}\n" );

                    out.write( "var id = obj.id ;\n" );
                    out.write( "var informationAreaObject = document.getElementById( 'information' ) ;\n" );

                    out.write( "for( var i = 0 ; i < informationAreaObject.childNodes.length ; i ++ )\n" );
                    out.write( "{\n" );
                    out.write( "var temp = informationAreaObject.childNodes[ i ] ;\n" );

                    out.write( "if( temp.tagName == 'DIV' )\n" );
                    out.write( "{\n" );
                    out.write( "temp.style.display = 'none' ;\n" );
                    out.write( "}\n" );
                    out.write( "}\n" );

                    out.write( "if( id.substring( 0 , 6 ) == 'system' )\n" );
                    out.write( "{\n" );
                    out.write( "document.getElementById( 'system' + id.substring( id.indexOf( '_' ) + 1 ) ).style.display = '' ;\n" );
                    out.write( "}\n" );
                    out.write( "else if( id.substring( 0 , 9 ) == 'subsystem' ) \n" );
                    out.write( "{\n" );
                    out.write( "document.getElementById( 'subsystem' + id.substring( id.indexOf( '_' ) + 1 ) ).style.display = '' ;\n" );
                    out.write( "}\n" );
                    out.write( "else if( id.substring( 0 , 9 ) == 'component' )\n" );
                    out.write( "{\n" );
                    out.write( "document.getElementById( 'component' + id.substring( id.indexOf( '_' ) + 1 ) ).style.display = '' ;\n" );
                    out.write( "}\n" );
                    out.write( "else\n" );
                    out.write( "{\n" );
                    out.write( "document.getElementById( 'subcomponent' + id.substring( id.indexOf( '_' ) + 1 ) ).style.display = '' ;\n" );
                    out.write( "}\n" );
                    out.write( "}\n" );

                    out.write( "</script>\n" );

                    out.write( "</head>\n" );

                    out.write( "<body style = 'font-family:arial'>\n" );

                    out.write( "<center><h3> COINCOMO Project </h3></center>\n" );

                    out.write( "<table border = '1' rules = 'group' width = '95%' align = 'center' cellpadding = '15'>\n" );
                    out.write( "<tr>\n" );
                    out.write( "<td width = '20%' valign = 'top' style = 'font-family:arial'>\n" );
                    out.write( "<ul style = 'padding-left:5px' >\n" );

                    out.write( "<a class = 'system' id = 'system_" + system.getUnitID() + "' href = '#' onclick = 'return displayInformation( event )'> " + system.getName() + " </a>\n" );

                    out.write( "<ul style = 'padding-left:16px' type = 'disc' >\n" );

                    Vector<COINCOMOUnit> orderedSubSystemsVector = GlobalMethods.getOrderedVector( system.getListOfSubUnits() );

                    for ( int i = 0 ; i < orderedSubSystemsVector.size() ; i++ )
                    {
                        COINCOMOSubSystem subSystem = (COINCOMOSubSystem) orderedSubSystemsVector.get( i );

                        out.write( "<li><a class = 'subsystem' id = 'subsystem_" + subSystem.getUnitID() + "' href = '#' onclick = 'return displayInformation( event )'> " + subSystem.getName() + " </a></li>\n" );

                        out.write( "<ul style = 'padding-left:16px' type = 'square' >\n" );


                        Vector<COINCOMOUnit> orderedComponentsVector = GlobalMethods.getOrderedVector( subSystem.getListOfSubUnits() );

                        for ( int j = 0 ; j < orderedComponentsVector.size() ; j++ )
                        {
                            COINCOMOComponent component = (COINCOMOComponent) orderedComponentsVector.get( j );

                            out.write( "<li><a class = 'component' id = 'component_" + component.getUnitID() + "' href = '#' onclick = 'return displayInformation( event )'> " + component.getName() + " </a> </li>\n" );

                            out.write( "<ul style = 'padding-left:16px' type = 'circle' >\n" );

                            Vector<COINCOMOUnit> orderedSubComponentsVector = GlobalMethods.getOrderedVector( component.getListOfSubUnits() );

                            for ( int c = 0 ; c < orderedSubComponentsVector.size() ; c++ )
                            {
                                COINCOMOSubComponent subComponent = (COINCOMOSubComponent) orderedSubComponentsVector.get( c );

                                out.write( "<li><a class = 'subcomponent' id = 'subcomponent_" + subComponent.getUnitID() + "' href = '#' onclick = 'return displayInformation( event )'> " + subComponent.getName() + " </a></li>\n" );
                            }

                            out.write( "</ul>\n" );
                        }

                        out.write( "</ul>\n" );
                    }

                    out.write( "</ul>\n" );
                    out.write( "</ul>\n" );

                    out.write( "</td>\n" );

                    out.write( "<td width = '80%' style = 'font-family:arial'>\n" );

                    out.write( "<div id = 'information' >\n" );

                    out.write( "<div style = 'display:none;' id = 'system" + system.getUnitID() + "' >\n" );
                    out.write( "<table border = '1' width = '90%' align = 'center'>\n" );

                    out.write( "<tr>\n" );
                    out.write( "<th width = '30%' bgcolor = '#CCCCCC' > ID </th>\n" );
                    out.write( "<td align = 'center' > " + system.getUnitID() + " </td>\n" );
                    out.write( "</tr>\n" );
                    out.write( "<tr>\n" );
                    out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Name </th>\n" );
                    out.write( "<td align = 'center' > " + system.getName() + " </td>\n" );
                    out.write( "</tr>\n" );
                    out.write( "<tr>\n" );
                    out.write( "<th width = '30%' bgcolor = '#CCCCCC' > SLOC </th>\n" );
                    out.write( "<td align = 'center' > " + system.getFinalSLOC() + " </td>\n" );
                    out.write( "</tr>\n" );
                    out.write( "<tr>\n" );
                    out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Staff </th>\n" );
                    out.write( "<td align = 'center' > " + format1Decimal.format( GlobalMethods.roundOff( system.getStaff() , 1 ) ) + " </td>\n" );
                    out.write( "</tr>\n" );
                    out.write( "<tr>\n" );
                    out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Cost </th>\n" );
                    out.write( "<td align = 'center' > $" + format2Decimals.format( GlobalMethods.roundOff( system.getCost() , 2 ) ) + " </td>\n" );
                    out.write( "</tr>\n" );

                    out.write( "</table>\n" );
                    out.write( "</div>\n" );

                    for ( int i = 0 ; i < orderedSubSystemsVector.size() ; i++ )
                    {
                        COINCOMOSubSystem subSystem = (COINCOMOSubSystem) orderedSubSystemsVector.get( i );

                        out.write( "<div style = 'display:none' id = 'subsystem" + subSystem.getUnitID() + "' >\n" );
                        out.write( "<table border = '1' width = '90%' align = 'center'>\n" );

                        out.write( "<tr>\n" );
                        out.write( "<th width = '30%' bgcolor = '#CCCCCC' > ID </th>\n" );
                        out.write( "<td align = 'center' > " + subSystem.getUnitID() + " </td>\n" );
                        out.write( "</tr>\n" );
                        out.write( "<tr>\n" );
                        out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Name </th>\n" );
                        out.write( "<td align = 'center' > " + subSystem.getName() + " </td>\n" );
                        out.write( "</tr>\n" );
                        out.write( "<tr>\n" );
                        out.write( "<th width = '30%' bgcolor = '#CCCCCC' > SLOC </th>\n" );
                        out.write( "<td align = 'center' > " + subSystem.getFinalSLOC() + " </td>\n" );
                        out.write( "</tr>\n" );
                        out.write( "<tr>\n" );
                        out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Staff </th>\n" );
                        out.write( "<td align = 'center' > " + format1Decimal.format( GlobalMethods.roundOff( subSystem.getStaff() , 1 ) ) + " </td>\n" );
                        out.write( "</tr>\n" );
                        out.write( "<tr>\n" );
                        out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Cost </th>\n" );
                        out.write( "<td align = 'center' > $" + format2Decimals.format( GlobalMethods.roundOff( subSystem.getCost() , 2 ) ) + " </td>\n" );
                        out.write( "</tr>\n" );

                        out.write( "</table>\n" );
                        out.write( "</div>\n" );

                        Vector<COINCOMOUnit> orderedComponentsVector = GlobalMethods.getOrderedVector( subSystem.getListOfSubUnits() );

                        for ( int j = 0 ; j < orderedComponentsVector.size() ; j++ )
                        {
                            COINCOMOComponent component = (COINCOMOComponent) orderedComponentsVector.get( j );

                            out.write( "<div style = 'display:none' id = 'component" + component.getUnitID() + "' >\n" );
                            out.write( "<table border = '1' width = '90%' align = 'center'>\n" );

                            out.write( "<tr>\n" );
                            out.write( "<th width = '30%' bgcolor = '#CCCCCC' > ID </th>\n" );
                            out.write( "<td align = 'center' > " + component.getUnitID() + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Name </th>\n" );
                            out.write( "<td align = 'center' > " + component.getName() + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '30%' bgcolor = '#CCCCCC' > SLOC </th>\n" );
                            out.write( "<td align = 'center' > " + component.getFinalSLOC() + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Staff </th>\n" );
                            out.write( "<td align = 'center' > " + format1Decimal.format( GlobalMethods.roundOff( component.getStaff() , 1 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Cost </th>\n" );
                            out.write( "<td align = 'center' > $" + format2Decimals.format( GlobalMethods.roundOff( component.getCost() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Total Effort </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( component.getTotalEffort() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Total Inst Cost </th>\n" );
                            out.write( "<td align = 'center' > " + format3Decimals.format( GlobalMethods.roundOff( component.getTotalInstCost() , 3 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '30%' bgcolor = '#CCCCCC' > PROD </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( component.getTotalProd() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Total Schedule </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( component.getTotalSchedule() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Scale Factor </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( component.getScaleFactor() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );

                            out.write( "</table>\n" );

                            out.write( "<br />\n" );

                            out.write( "<table border = '0' width = '90%' align = 'center'>\n" );

                            out.write( "<tr>\n" );
                            out.write( "<td style = 'font-family:arial'>\n" );

                            out.write( "<table border = '1' width = '100%' align = 'center'>\n" );

                            out.write( "<caption> Inception </caption>\n" );

                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Effort </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getInceptionPM() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Month </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getInceptionM() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Personnel </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getInceptionP() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Effort% </th>\n" );
                            out.write( "<td align = 'center' > " + component.getInceptionEffortPercentage() + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Schedule% </th>\n" );
                            out.write( "<td align = 'center' > " + component.getInceptionSchedulePercentage() + " </td>\n" );
                            out.write( "</tr>\n" );

                            out.write( "</table>\n" );
                            out.write( "</td>\n" );
                            out.write( "<td style = 'font-family:arial'>\n" );

                            out.write( "<table border = '1' width = '100%' align = 'center'>\n" );

                            out.write( "<caption> Elaboration </caption>\n" );

                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Effort </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getElaborationPM() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Month </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getElaborationM() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Personnel </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getElaborationP() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Effort% </th>\n" );
                            out.write( "<td align = 'center' > " + component.getElaborationEffortPercentage() + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Schedule% </th>\n" );
                            out.write( "<td align = 'center' > " + component.getElaborationSchedulePercentage() + " </td>\n" );
                            out.write( "</tr>\n" );


                            out.write( "</table>\n" );
                            out.write( "</td>\n" );
                            out.write( "<td style = 'font-family:arial'>\n" );

                            out.write( "<table border = '1' width = '100%' align = 'center'>\n" );

                            out.write( "<caption> Construction </caption>\n" );

                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Effort </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getConstructionPM() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Month </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getConstructionM() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Personnel </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getConstructionP() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Effort% </th>\n" );
                            out.write( "<td align = 'center' > " + component.getConstructionEffortPercentage() + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Schedule% </th>\n" );
                            out.write( "<td align = 'center' > " + component.getConstructionSchedulePercentage() + " </td>\n" );
                            out.write( "</tr>\n" );

                            out.write( "</table>\n" );
                            out.write( "</td>\n" );
                            out.write( "<td style = 'font-family:arial'>\n" );

                            out.write( "<table border = '1' width = '100%' align = 'center'>\n" );

                            out.write( "<caption> Transition </caption>\n" );

                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Effort </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getTransitionPM() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Month </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getTransitionM() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Personnel </th>\n" );
                            out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( (float)component.getTransitionP() , 2 ) ) + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Effort% </th>\n" );
                            out.write( "<td align = 'center' > " + component.getTransitionEffortPercentage() + " </td>\n" );
                            out.write( "</tr>\n" );
                            out.write( "<tr>\n" );
                            out.write( "<th width = '50%' bgcolor = '#CCCCCC' > Schedule% </th>\n" );
                            out.write( "<td align = 'center' > " + component.getTransitionSchedulePercentage() + " </td>\n" );
                            out.write( "</tr>\n" );


                            out.write( "</table>\n" );
                            out.write( "</td>\n" );
                            out.write( "</tr>\n" );

                            out.write( "</table>\n" );
                            out.write( "</div>\n" );

                            Vector<COINCOMOUnit> orderedSubComponentsVector = GlobalMethods.getOrderedVector( component.getListOfSubUnits() );

                            for ( int c = 0 ; c < orderedSubComponentsVector.size() ; c++ )
                            {
                                COINCOMOSubComponent subComponent = (COINCOMOSubComponent) orderedSubComponentsVector.get( c );


                                out.write( "<div style = 'display:none' id = 'subcomponent" + subComponent.getUnitID() + "' >\n" );
                                out.write( "<table border = '1' width = '90%' align = 'center'>\n" );

                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > ID </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getUnitID() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Name </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getName() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > SLOC </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getFinalSLOC() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Staff </th>\n" );
                                out.write( "<td align = 'center' > " + format1Decimal.format( GlobalMethods.roundOff( subComponent.getStaff() , 1 ) ) + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Cost </th>\n" );
                                out.write( "<td align = 'center' > $" + format2Decimals.format( GlobalMethods.roundOff( subComponent.getCost() , 2 ) ) + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Language </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getLanguage() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > EAF </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getEaf() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Labor Rate </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getLaborRate() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Nominal Effort </th>\n" );
                                out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( subComponent.getNomEffort() , 2 ) ) + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Estimated Effort </th>\n" );
                                out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( subComponent.getEstEffort() , 2 ) ) + " </td>\n" );
                                out.write( "</tr>\n" );

                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > PROD </th>\n" );
                                out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( subComponent.getProd() , 2 ) ) + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > RISK </th>\n" );
                                out.write( "<td align = 'center' > " + format2Decimals.format( GlobalMethods.roundOff( subComponent.getRisk() , 2 ) ) + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Assessment & Assimiliation </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getAssementAssimilation() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Auto Translation Productivity </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getAutoTranslationProductivity() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Automatically Translated </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getAutomaticallyTranslated() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Breakage </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getBreakage() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Change Multiplier </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getChangeMultiplier() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Code Modified </th>\n" );
                                out.write( "<td align = 'center' > %" + subComponent.getCodeModified() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Design Modified </th>\n" );
                                out.write( "<td align = 'center' > %" + subComponent.getDesignModified() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Integration Modified </th>\n" );
                                out.write( "<td align = 'center' > %" + subComponent.getIntegrationModified() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Software Understanding </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getSoftwareUnderstanding() + " </td>\n" );
                                out.write( "</tr>\n" );
                                out.write( "<tr>\n" );
                                out.write( "<th width = '30%' bgcolor = '#CCCCCC' > Unfamiliarity </th>\n" );
                                out.write( "<td align = 'center' > " + subComponent.getUnfamiliarity() + " </td>\n" );
                                out.write( "</tr>\n" );

                                out.write( "</table>\n" );

                                out.write( "</div>\n" );
                            }
                        }
                    }

                    out.write( "</div>\n" );

                    out.write( "</td>\n" );
                    out.write( "</tr>\n" );
                    out.write( "</table>\n" );

                    out.write( "<center><h6> University of Southern California, All Rights Reserved. </h6></center>\n" );

                    out.write( "</body>\n" );

                    out.write( "</html>\n" );

                    out.flush();

                    // Free Resources ..
                    out.close();

                    GlobalMethods.updateStatusBar( "Exporting had Finished." );
                }
                else
                {
                    GlobalMethods.updateStatusBar( "File has to be an HTML Document." , Color.RED );
                }

            }

        }
        catch ( IOException e )
        {
        }
        finally
        {
            // Go Back to Default
            setJavaUI();
        }

    }

    public static void exportProjectAsXML()
    {
        if ( HierarchyPanel.root == null )
        {
            GlobalMethods.updateStatusBar( "No System has been Opened to read from" , Color.RED );

            return;
        }

        try
        {
            JFileChooser fc = new JFileChooser();

            // For Example, Windows OS's UI
            setOperatingSystemUI();

            fc.updateUI();

            GlobalMethods.updateStatusBar( "Done." );

            fc.setSelectedFile( new File( "Project.xml" ) );

            // Show open dialog; this method does not return until the dialog is closed
            int result = fc.showSaveDialog( COINCOMO.application );

            if ( result == JFileChooser.APPROVE_OPTION )
            {
                // Has to be an XML Document
                if ( fc.getSelectedFile().getName().endsWith( ".xml" ) )
                {
                    BufferedWriter out = new BufferedWriter( new FileWriter( fc.getSelectedFile() ) );

                    COINCOMOSystem system = (COINCOMOSystem) HierarchyPanel.root.getCOINCOMOUnit();

                    out.write( "<COINCOMO>\n" );

                    out.write( "\t<System>\n" );
                    out.write( "\t<id>" + system.getUnitID() + "</id>\n" );
                    out.write( "\t<name>" + system.getName() + "</name>\n" );
                    out.write( "\t<sloc>" + system.getFinalSLOC() + "</sloc>\n" );
                    out.write( "\t<cost>" + system.getCost() + "</cost>\n" );
                    out.write( "\t<staff>" + system.getStaff() + "</staff>\n" );

                    Vector<COINCOMOUnit> orderedSubSystemsVector = GlobalMethods.getOrderedVector( system.getListOfSubUnits() );

                    for ( int i = 0 ; i <
                            orderedSubSystemsVector.size() ; i++ )
                    {
                        COINCOMOSubSystem subSystem = (COINCOMOSubSystem) orderedSubSystemsVector.get( i );

                        out.write( "\t\t<SubSystem>\n" );
                        out.write( "\t\t<id>" + subSystem.getUnitID() + "</id>\n" );
                        out.write( "\t\t<name>" + subSystem.getName() + "</name\n>" );
                        out.write( "\t\t<sloc>" + subSystem.getFinalSLOC() + "</sloc>\n" );
                        out.write( "\t\t<cost>" + subSystem.getCost() + "</cost>\n" );
                        out.write( "\t\t<staff>" + subSystem.getStaff() + "</staff>\n" );
                        

                        Vector<COINCOMOUnit> orderedComponentsVector = GlobalMethods.getOrderedVector( subSystem.getListOfSubUnits() );

                        for ( int j = 0 ; j <
                                orderedComponentsVector.size() ; j++ )
                        {
                            COINCOMOComponent component = (COINCOMOComponent) orderedComponentsVector.get( j );

                            out.write( "\t\t\t<Component>\n" );
                            out.write( "\t\t\t<id>" + component.getUnitID() + "</id>\n" );
                            out.write( "\t\t\t<name>" + component.getName() + "</name>\n" );
                            out.write( "\t\t\t<sloc>" + component.getFinalSLOC() + "</sloc>\n" );
                            out.write( "\t\t\t<cost>" + component.getCost() + "</cost>\n" );
                            out.write( "\t\t\t<staff>" + component.getStaff() + "</staff>\n" );
                            out.write( "\t\t\t<effort>" + component.getTotalEffort() + "</effort>\n" );
                            out.write( "\t\t\t<instCost>" + component.getTotalInstCost() + "</instCost>\n" );
                            out.write( "\t\t\t<prod>" + component.getTotalProd() + "</prod>\n" );
                            out.write( "\t\t\t<schedule>" + component.getTotalSchedule() + "</schedule>\n" );
                            out.write( "\t\t\t<scaleFactor>" + component.getScaleFactor() + "</scaleFactor>\n" );
                            out.write( "\t\t\t<inception>\n" );
                            out.write( "\t\t\t\t<effort>" + component.getInceptionPM() + "</effort>\n" );
                            out.write( "\t\t\t\t<month>" + component.getInceptionM() + "</month>\n" );
                            out.write( "\t\t\t\t<personnel>" + component.getInceptionP() + "</personnel>\n" );
                            out.write( "\t\t\t\t<effortPercentage>" + component.getInceptionEffortPercentage() + "</effortPercentage>\n" );
                            out.write( "\t\t\t\t<schedulePercentage>" + component.getInceptionSchedulePercentage() + "</schedulePercentage>\n" );
                            out.write( "\t\t\t</inception>\n" );
                            out.write( "\t\t\t<elaboration>\n" );
                            out.write( "\t\t\t\t<effort>" + component.getElaborationPM() + "</effort>\n" );
                            out.write( "\t\t\t\t<month>" + component.getElaborationM() + "</month>\n" );
                            out.write( "\t\t\t\t<personnel>" + component.getElaborationP() + "</personnel>\n" );
                            out.write( "\t\t\t\t<effortPercentage>" + component.getElaborationEffortPercentage() + "</effortPercentage>\n" );
                            out.write( "\t\t\t\t<schedulePercentage>" + component.getElaborationSchedulePercentage() + "</schedulePercentage>\n" );
                            out.write( "\t\t\t</elaboration>\n" );
                            out.write( "\t\t\t<construction>\n" );
                            out.write( "\t\t\t\t<effort>" + component.getConstructionPM() + "</effort>\n" );
                            out.write( "\t\t\t\t<month>" + component.getConstructionM() + "</month>\n" );
                            out.write( "\t\t\t\t<personnel>" + component.getConstructionP() + "</personnel>\n" );
                            out.write( "\t\t\t\t<effortPercentage>" + component.getConstructionEffortPercentage() + "</effortPercentage>\n" );
                            out.write( "\t\t\t\t<schedulePercentage>" + component.getConstructionSchedulePercentage() + "</schedulePercentage>\n" );
                            out.write( "\t\t\t</construction>\n" );
                            out.write( "\t\t\t<transition>\n" );
                            out.write( "\t\t\t\t<effort>" + component.getTransitionPM() + "</effort>\n" );
                            out.write( "\t\t\t\t<month>" + component.getTransitionM() + "</month>\n" );
                            out.write( "\t\t\t\t<personnel>" + component.getTransitionP() + "</personnel>\n" );
                            out.write( "\t\t\t\t<effortPercentage>" + component.getTransitionEffortPercentage() + "</effortPercentage>\n" );
                            out.write( "\t\t\t\t<schedulePercentage>" + component.getTransitionSchedulePercentage() + "</schedulePercentage>\n" );
                            out.write( "\t\t\t</transition>\n" );

                            Vector<COINCOMOUnit> orderedSubComponentsVector = GlobalMethods.getOrderedVector( component.getListOfSubUnits() );

                            for ( int c = 0 ; c <
                                    orderedSubComponentsVector.size() ; c++ )
                            {
                                COINCOMOSubComponent subComponent = (COINCOMOSubComponent) orderedSubComponentsVector.get( c );

                                out.write( "\t\t\t\t<SubComponent>\n" );
                                out.write( "\t\t\t\t<id>" + subComponent.getUnitID() + "</id>\n" );
                                out.write( "\t\t\t\t<name>" + subComponent.getName() + "</name>\n" );
                                out.write( "\t\t\t\t<language>" + subComponent.getLanguage() + "</language>\n" );
                                out.write( "\t\t\t\t<sloc>" + subComponent.getFinalSLOC() + "</sloc>\n" );
                                out.write( "\t\t\t\t<cost>" + subComponent.getCost() + "</cost>\n" );
                                out.write( "\t\t\t\t<staff>" + subComponent.getStaff() + "</staff>\n" );
                                out.write( "\t\t\t\t<eaf>" + subComponent.getEaf() + "</eaf>\n" );
                                out.write( "\t\t\t\t<laborRate>" + subComponent.getLaborRate() + "</laborRate>\n" );
                                out.write( "\t\t\t\t<nomEffort>" + subComponent.getNomEffort() + "</nomEffort>\n" );
                                out.write( "\t\t\t\t<estEffort>" + subComponent.getEstEffort() + "</estEffort>\n" );
                                out.write( "\t\t\t\t<prod>" + subComponent.getProd() + "</prod>\n" );
                                out.write( "\t\t\t\t<risk>" + subComponent.getRisk() + "</risk>\n" );
                                out.write( "\t\t\t\t<assessmentAssimilation>" + subComponent.getAssementAssimilation() + "</assessmentAssimilation>\n" );
                                out.write( "\t\t\t\t<autoTranslationProductivity>" + subComponent.getAutoTranslationProductivity() + "</autoTranslationProductivity>\n" );
                                out.write( "\t\t\t\t<automaticallyTranslated>" + subComponent.getAutomaticallyTranslated() + "</automaticallyTranslated>\n" );
                                out.write( "\t\t\t\t<breakage>" + subComponent.getBreakage() + "</breakage>\n" );
                                out.write( "\t\t\t\t<changeMultiplier>" + subComponent.getChangeMultiplier() + "</changeMultiplier>\n" );
                                out.write( "\t\t\t\t<codeModified>" + subComponent.getCodeModified() + "</codeModified>\n" );
                                out.write( "\t\t\t\t<designModified>" + subComponent.getDesignModified() + "</designModified>\n" );
                                out.write( "\t\t\t\t<integrationModified>" + subComponent.getIntegrationModified() + "</integrationModified>\n" );
                                out.write( "\t\t\t\t<softwareUnderstanding>" + subComponent.getSoftwareUnderstanding() + "</softwareUnderstanding>\n" );
                                out.write( "\t\t\t\t<unfamiliarity>" + subComponent.getUnfamiliarity() + "</unfamiliarity>\n" );
                                out.write( "\t\t\t\t</SubComponent>\n" );
                            }

                            out.write( "\t\t\t</Component>\n" );
                        }

                        out.write( "\t\t</SubSystem>\n" );
                        
                        out.write( "\t\t<Cocot>\n" );
                        out.write( "\t\t<id>" + subSystem.getProjectID() + "</id>\n" );
                        out.write( "\t\t<name>" + subSystem.getProjectName() + "</name\n>" );
                        out.write( "\t\t<originator>" + subSystem.getProjectOriginator() + "</originator>\n" );
                        out.write( "\t\t<date>" + subSystem.getDateString() + "</name\n>" );
                        out.write( "\t\t<ksloc>" + subSystem.getKSLOC() + "</ksloc>\n" );
                        out.write( "\t\t<crevol>" + subSystem.getCREVOL() + "</crevol>\n" );
                        String cotsClassess = "";
                        int j = 0;
                        for(String s : subSystem.getXMLCotClass())
                        {	
                        	j++;
                        	if( (j+1) < subSystem.getXMLCotClass().size())
                        		cotsClassess += s + " , ";
                        	else
                        		cotsClassess += s;
                        	
                        		
                        }
                        out.write( "\t\t<cots>" + cotsClassess + "</cots>\n" );
                        out.write( "\t\t<projresult>" + subSystem.getProjectResult() + "</projresult>\n" );
                        out.write( "\t\t</Cocot>\n" );
                        
                    }

                    out.write( "\t</System>\n" );

                    out.write( "</COINCOMO>" );
                    out.flush();

                    // Free Resources ..
                    out.close();

                    GlobalMethods.updateStatusBar( "Exporting had Finished." );
                }
                else
                {
                    GlobalMethods.updateStatusBar( "File has to be an XML Document." , Color.RED );
                }

            }
        }
        catch ( IOException e )
        {
        }
        finally
        {
            // Go Back to Default
            setJavaUI();
        }
    }

    public static void showAboutUsDialog()
    {
        new AboutUsDialog( COINCOMO.application );
    }

    public static void showEAFDialog()
    {
        new EAFDialog( COINCOMO.application );
    }

    public static void showScaleFactorsDialog()
    {
        new ScaleFactorsDialog( COINCOMO.application );
    }

    public static void showEquationEditorDialog()
    {
        new EquationEditorDialog( COINCOMO.application );
    }

    public static void showFunctionPointsDialog()
    {
        new FunctionPointsDialog( COINCOMO.application );
    }

    public static void showPersonMonthDialog()
    {
        GlobalMethods.updateStatusBar( "Done." );

        JOptionPane.showInputDialog( COINCOMO.application , "Please Enter Hours/Person Month:" );
    }

// -----------------------------------------------
// Private Methods ...
    private static void setOperatingSystemUI()
    {
        try
        {
            UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
        }
        catch ( Exception ex )
        {
        }
    }

    private static void setJavaUI()
    {
        try
        {
            UIManager.setLookAndFeel( defaultUI );
        }
        catch ( Exception ex )
        {
        }
    }

}
